<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-apiConfig-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">对应路由id：</label>
            <div class="col-sm-8">
                <input id="serviceId" name="serviceId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">环境：</label>
            <div class="col-sm-8">
                <div class="input-group" style="width: 100%">
                    <select name="environment" class="form-control m-b"
                            th:with="type=${@dict.getType('sys_apiconfig_environment')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">请求方法：</label>
            <div class="col-sm-8">
                <div class="input-group" style="width: 100%">
                    <select name="methodType" class="form-control m-b"
                            th:with="type=${@dict.getType('sys_apiconfig_method')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input id="title" name="title" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">接口描述：</label>
            <div class="col-sm-8">
                <input id="desc" name="desc" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">需要校验的字段(只能校验非null)：</label>
            <div class="col-sm-8">
                <input id="validateParams" name="validateParams" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权限配置：</label>
            <div class="col-sm-8">
                <div class="onoffswitch">
                    <input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="auth-state">
                    <label class="onoffswitch-label" for="auth-state">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>接口地址：</label>
            <div class="col-sm-8">
                <input id="patternUrl" name="patternUrl" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">并发量：</label>
            <div class="col-sm-8">
                <input id="replenishRate" name="replenishRate" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">并发容量：</label>
            <div class="col-sm-8">
                <input id="burstCapacity" name="burstCapacity" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="onoffswitch">
                    <input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="api-state">
                    <label class="onoffswitch-label" for="api-state">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">额外参数(json格式)：</label>
            <div class="col-sm-8">
                <input id="extra" name="extra" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "system/apiConfig"
    $("#form-apiConfig-add").validate({
        rules: {
            xxxx: {
                required: true,
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $('#form-apiConfig-add').serializeArray();
            var state = $("input[id='api-state']").is(':checked') == true ? 1 : 0;
            var authType = $("input[id='auth-state']").is(':checked') == true ? 1 : 0;
            data.push({"name": "state", "value": state});
            data.push({"name": "authType", "value": authType});
            $.operate.save(prefix + "/add", data);
        }
    }
</script>
</body>
</html>
